package icbc.nav.control
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.DropShadowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	import icbc.app.AppGlobal;
	import icbc.app.AppText;
	
	public class SubContentLabel extends Sprite
	{
		private static const TXT_CHILD_NAME:String = "txt";
		private static const FONT_SIZE:uint = 14;
		private static const FONT_COLOR:uint = 0xE381B2;
		private static const TEXT_HEIGHT:uint = 16;
		private var controlWidth:uint;
		private var controlHeight:uint;
		private var borderColor:uint = 0xAAAAAA;
		private var baseColor:uint = 0xffffff;
		private var baseRedColor:uint = 0xC52027;

		private var main:Sprite = new Sprite();
		private var base:Sprite = new Sprite();
		private var panel:Sprite;

		public function SubContentLabel(vWidth:uint, vHeight:uint)
		{
			super();
			controlWidth = vWidth;
			controlHeight = vHeight;
			addChild(main);
			main.addChild(base);
			addEventListener(Event.ADDED_TO_STAGE, initStage);
		}
		
		private function initStage(evt:Event):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, initStage);
			display();
		}
		
		private function display():void
		{
			buildBase();
		}
		
		private function build(item:Sprite, bgColor:uint, textColor:uint):void
		{
			setRootBase(item, bgColor, textColor);
		}
		
		private function setRootBase(item:Sprite, bgColor:uint, textColor:uint):void
		{
			var rounded:uint = 0;
			//item.graphics.lineStyle(0, borderColor);
			item.graphics.beginFill(bgColor,0);
			item.graphics.drawRoundRect(0, 0, controlWidth, controlHeight, rounded, rounded);
			item.graphics.endFill();
			
			var itemtxt:TextField = buildText( {
				width : controlWidth,
				height : TEXT_HEIGHT,
				text : AppText.MAS_PANTALLAS,
				color : textColor
			} );
			itemtxt.name = TXT_CHILD_NAME;
			item.addChild(itemtxt);
			itemtxt.x = controlWidth/2 - itemtxt.width/2;
			itemtxt.y = controlHeight/2 - itemtxt.height/2;
			item.alpha = 0;
		}
		
		private function buildText(config:Object) : TextField
		{
			var textSize:uint = FONT_SIZE;
			var textAlign:String = "center";
			var autoSize:String = TextFieldAutoSize.CENTER;
			var text:String = (config.text != undefined)?config.text:"";
			var width:uint = (config.width != undefined)?config.width:120;
			var height:uint = (config.height != undefined)?config.height:18;
			var color:uint = (config.color != undefined)?config.color:0xffffff;
			var format:TextFormat = new TextFormat();
			format.font = AppGlobal.FONT_NAME;
			format.color = color;
			format.size = textSize;
			format.align = textAlign;
			var txt:TextField = new TextField();
			txt.selectable = false;
			txt.defaultTextFormat = format;
			txt.autoSize = autoSize;
			txt.text = text;
			return txt;
		}
		
		private function buildBase():void
		{
			build(base, 0xffffff, baseRedColor);
			base.alpha = 1;
		}
	}
}